import { createRouter, createWebHashHistory } from 'vue-router'
import Layout from '../layout/Layout'
import Login from '../views/Login'
import Model from '../views/Model'
import Personal from '../views/Personal'
import Home from '../views/Home'


const routes = [
  { path: '/', component: Login },
  { path: '/login', component: Login },
  {
    path: '/layout',
    component: Layout,
    redirect: '/home',
    children: [
      { path: '/home', component: Home },
      { path: '/model', component: Model },
      { path: '/personal', component: Personal },
    ]
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})


// 挂载路由导航守卫
// router.beforeEach((to, from, next) => {
//   // to 需要访问的路径
//   // from 从哪跳转
//   // next 放行，next('/login')强制跳转
//   if (to.path === '/login') return next()
//   // 获取token
//   const tokenStr = window.sessionStorage.getItem('token')
//   if (!tokenStr) {
//     return next('/login')
//   } else {
//     next()
//   }
// })

export default router
